package fr.p10.miage.robot;

import java.util.concurrent.Semaphore;

public class SlotAttente extends Slot {

	Semaphore semaphore = new Semaphore(1, true);

	public SlotAttente(int idSlot) {
		super(idSlot);
	}

	@Override
	// ** Un robot se place sur le slot
	public void sePlacer(Robot r) {
		r.setSlotEnPlace(this);

		this.robotPlace = r;
		try {
			synchronized (this) {
				this.semaphore.acquire();
				Base.getInstance().slotRecharge.sePlacer(r);
				this.semaphore.release();
			}
		} catch (final InterruptedException e) {
			e.printStackTrace();
		}
	}

	@Override
	public String toString() {
		if (this.isOccupe()) {
			return "* Slot d'attente " + this.idSlot + " : robot " + this.robotPlace.getIdRobot();
		} else {
			return "* Slot d'attente " + this.idSlot + " : vide";
		}
	}
}